#coding:UTF8
import numpy as np

ts = [0.9, 0.5, 0.4, 0.8, 0.9, 0.5, 0.4, 0.8, 0.9, 0.5, 0.4, 0.8, 0.9, 0.5, 0.4, 0.8, 0.9, 0.5, 0.4, 0.8]

def create(ts):
    edges = []
    i, j, second = 0, 1, None
    while i < (len(ts) - 1):
        if j==1: second = ts[i + j]
        
        '''遇到更高点， i前进'''
        if ts[i + j] >= ts[i]:
            edges.append((i, i + j))
            i, j = i + 1, 1
        else:
            '''可视检测'''
            if ts[i + j] >= second: 
                second = ts[i + j]
                edges.append((i, i + j))
            j += 1
            '''虽未遇到高点，但已末尾'''
            if i + j == (len(ts)): i, j = i + 1, 1
        '''End else'''
    '''End while'''
    for e in edges:
        print e[0] + 1, e[1] + 1     
'''End def create'''     
             
# create(ts)

def calc():
    X = [2, 3, 4]
    Y = [0.75, 0.1, 0.05]
    ps = np.polyfit(X, Y, 1)  #一次多项式拟合，相当于线性拟合
    p1 = np.poly1d(ps)
    print ps 
    print p1
 
calc()


